package com.huawei.appmarket.service.store.awk.card;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.ConstraintLayout.LayoutParams;
import com.huawei.appgallery.foundation.card.base.bean.BaseDistCardBean;
import com.huawei.appgallery.foundation.card.base.normal.bean.NormalCardBean;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.appgallery.foundation.ui.framework.widget.button.DownloadButton;
import com.huawei.appgallery.horizontalcard.api.card.BaseHorizontalItemCard;
import com.huawei.appmarket.service.store.awk.bean.HorizonalHomeCardItemBean;
import huawei.widget.HwTextView;
import o.cgz;
import o.chy;
import o.Logger;
import o.dof;
import o.ContentManager;
import o.eiu;
import o.eqx;
import o.eqz;
import o.erq;
import o.evx;
import o.ewm.d;
import o.ewm.j;
import o.fb;

public class HorizontalApplistSingleItemCard extends BaseHorizontalItemCard {
    private HwTextView ʻ;
    private TextView ʼ;
    private View ʽ;
    private TextView ˋ;
    private HwTextView ॱॱ;
    private ImageView ᐝ;

    public HorizontalApplistSingleItemCard(Context context) {
        super(context);
    }

    public cgz ˏ(View view) {
        ˏ((ImageView) view.findViewById(j.ʻˊ));
        ˊ((ImageView) view.findViewById(j.ꜞˋ));
        ॱ((TextView) view.findViewById(j.ʽ));
        ˊ((TextView) view.findViewById(j.ˋ));
        this.ॱॱ = (HwTextView) view.findViewById(j.ʼॱ);
        this.ʽ = view.findViewById(j.ᐝᐝ);
        this.ʻ = (HwTextView) view.findViewById(j.ꜟʽ);
        ˋ((DownloadButton) view.findViewById(j.ᵣ));
        this.ˋ = (TextView) view.findViewById(j.ॱⵈ);
        this.ᐝ = (ImageView) view.findViewById(j.ᐧʻ);
        this.ʼ = (TextView) view.findViewById(j.ㆍʼ);
        ʽ(view);
        return this;
    }

    public HorizonalHomeCardItemBean ʼ() {
        if (this.ˊᐝ != null) {
            return (HorizonalHomeCardItemBean) this.ˊᐝ;
        }
        return null;
    }

    public void ˏ(CardBean cardBean) {
        super.ˏ(cardBean);
        if (cardBean instanceof HorizonalHomeCardItemBean) {
            HorizonalHomeCardItemBean horizonalHomeCardItemBean = (HorizonalHomeCardItemBean) cardBean;
            if (this.ʿ != null) {
                if (horizonalHomeCardItemBean.v_() != null) {
                    this.ʿ.setVisibility(0);
                } else {
                    this.ʿ.setVisibility(4);
                }
            }
            ˊ(horizonalHomeCardItemBean);
            LayoutParams layoutParams = (LayoutParams) ˊˋ().getLayoutParams();
            if (dof.ʽ(horizonalHomeCardItemBean.ʽॱ())) {
                this.ʽ.setVisibility(8);
                if (this.ʻ != null) {
                    this.ʻ.setVisibility(8);
                }
                layoutParams.setMarginStart(this.ʼॱ.getResources().getDimensionPixelSize(d.ˏॱ));
            } else {
                try {
                    ˎ(this.ॱॱ);
                    this.ॱॱ.setText(ॱ(ʼ().ʽॱ()));
                    int parseInt = Integer.parseInt(ॱ(horizonalHomeCardItemBean.ʽॱ()));
                    String ॱ = eiu.ˏ().ॱ(parseInt);
                    if (ॱ == null) {
                        ʻ();
                    } else if (this.ʻ != null) {
                        ˋ(ॱ, parseInt);
                    }
                } catch (NumberFormatException e) {
                    Logger.e("HorizontalApplistSingleItemCard", "getAliasName_ NumberFormatException");
                    ʻ();
                }
            }
            ˋ(this.ʼ, horizonalHomeCardItemBean.ˋʻ());
        }
    }

    private void ˋ(final String str, final int i) {
        eqx.ॱ(ContentManager.getInstant().getContext(), str, new eqz(this) {
            final /* synthetic */ HorizontalApplistSingleItemCard ˏ;

            public void ॱ(Bitmap bitmap) {
                if (bitmap != null) {
                    this.ˏ.ˊ(bitmap, i);
                    return;
                }
                Logger.ˏ("HorizontalApplistSingleItemCard", "rank Image download failure:" + str);
                this.ˏ.ʻ();
            }
        });
    }

    private void ˊ(Bitmap bitmap, int i) {
        fb fbVar = new fb();
        fbVar.ˊ((ConstraintLayout) ˉ());
        fbVar.ˎ(j.ᐝᐝ, 8);
        if (this.ʻ != null) {
            if (i > 3) {
                fbVar.ˊ(j.ꜟʽ, (int) this.ʼॱ.getResources().getDimension(d.ॱʾ));
                this.ʻ.setText(String.valueOf(i));
                if (erq.ˏ(erq.ˎ(bitmap))) {
                    this.ʻ.setTextColor(this.ʼॱ.getResources().getColor(17170443));
                } else {
                    this.ʻ.setTextColor(this.ʼॱ.getResources().getColor(17170444));
                }
            } else {
                fbVar.ˊ(j.ꜟʽ, (int) this.ʼॱ.getResources().getDimension(d.ﹳ));
                this.ʻ.setText("");
            }
            fbVar.ˎ(j.ꜟʽ, 0);
            this.ʻ.setBackground(new BitmapDrawable(this.ʼॱ.getResources(), bitmap));
        }
        fbVar.ॱ(j.ʽ, 6, j.ˊˆ, 7, this.ʼॱ.getResources().getDimensionPixelSize(d.ˋ) + this.ʼॱ.getResources().getDimensionPixelSize(d.ﹳ));
        fbVar.ˋ((ConstraintLayout) ˉ());
    }

    private void ʻ() {
        this.ʽ.setVisibility(0);
        if (this.ʻ != null) {
            this.ʻ.setVisibility(8);
        }
        ((LayoutParams) ˊˋ().getLayoutParams()).setMarginStart(this.ʼॱ.getResources().getDimensionPixelSize(d.ߵ));
    }

    private void ˊ(HorizonalHomeCardItemBean horizonalHomeCardItemBean) {
        if (horizonalHomeCardItemBean.ٴ() != 0) {
            CharSequence ߴ = horizonalHomeCardItemBean.ߴ();
            if (dof.ˋ(ߴ)) {
                this.ˋ.setVisibility(4);
            } else {
                this.ˋ.setVisibility(0);
                this.ˋ.setText(ߴ);
            }
            String ՙ = horizonalHomeCardItemBean.ՙ();
            if (dof.ˋ(ՙ)) {
                this.ᐝ.setVisibility(8);
                return;
            }
            this.ᐝ.setVisibility(0);
            eqx.ˎ(this.ᐝ, ՙ);
            return;
        }
        this.ᐝ.setVisibility(8);
        if (dof.ʽ(horizonalHomeCardItemBean.ˎͺ())) {
            this.ˋ.setVisibility(4);
            return;
        }
        this.ˋ.setText(horizonalHomeCardItemBean.ˎͺ());
        this.ˋ.setVisibility(0);
    }

    private String ॱ(String str) {
        if (str.contains(".")) {
            return str.substring(0, str.indexOf("."));
        }
        return str;
    }

    private void ˎ(HwTextView hwTextView) {
        int dimensionPixelSize = hwTextView.getContext().getResources().getDimensionPixelSize(d.ˌ);
        int dimensionPixelSize2 = hwTextView.getContext().getResources().getDimensionPixelSize(d.ʽˋ);
        hwTextView.setTextSize(hwTextView.getContext().getResources().getDimension(d.ˈ));
        hwTextView.setAutoTextInfo(dimensionPixelSize, dimensionPixelSize2, 0);
    }

    public void ॱ(int i) {
        ˉ().setVisibility(i);
    }

    public void x_() {
        if (this.ˊᐝ instanceof BaseDistCardBean) {
            BaseDistCardBean baseDistCardBean = (BaseDistCardBean) this.ˊᐝ;
            if (baseDistCardBean.ͺ() == 1 || baseDistCardBean.ͺ() == 3) {
                this.ˉ.setText(baseDistCardBean.ॱˎ());
            } else if (!TextUtils.isEmpty(baseDistCardBean.ˏˎ())) {
                this.ˉ.setText(baseDistCardBean.ˏˎ());
            } else if (this.ˊᐝ instanceof NormalCardBean) {
                this.ˉ.setText(((NormalCardBean) this.ˊᐝ).ˏˏ());
            } else {
                this.ˉ.setText(baseDistCardBean.O_());
            }
        }
    }

    public void ॱ(final chy o_chy) {
        View ˉ = ˉ();
        if (ˉ != null) {
            ˉ.setOnClickListener(new evx(this) {
                final /* synthetic */ HorizontalApplistSingleItemCard ˋ;

                public void ˋ(View view) {
                    if (o_chy != null) {
                        o_chy.ˏ(0, this.ˋ);
                    }
                }
            });
        }
    }

    public void w_() {
        if (TextUtils.isEmpty(this.ˊᐝ.ॱˑ())) {
            eqx.ˏ(this.ʽॱ, this.ˊᐝ.ॱˌ(), "app_default_icon");
        } else {
            eqx.ॱ(this.ʽॱ, this.ˊᐝ.ॱˑ(), "app_default_icon");
        }
    }
}
